(module top (lib "eopl.ss" "eopl")
   (require "drscheme-init.scm")
;;-------------------------------------------------  
(require "duple.scm")

(define test-duple
  (lambda (tst n1 n2 ans)
    (eopl:printf "~s " tst)
    (let ((outcome
           (run-experiment duple (list n1 n2) ans
                           equal?)))
      (if (car outcome)
          (eopl:printf "passed ~%")
          (eopl:printf "Failed ~%")
          )
      )
    )
  )  
;;The Actual Tests
  (display "\n------------\nTesting Duple\n------------\n")  
(test-duple 'dupl1 2 3 '(3 3))
(test-duple 'dupl2 2 '(1 2) '((1 2) (1 2)))
(test-duple 'dupl3 0 3 '())



;;-------------------------------------------------  
;;1.17  Test for swapper
(require "swapper.scm")

(define test-swapper
(lambda(tst s1 s2 slist ans)
   (eopl:printf "~s " tst)
      (let ((outcome
             (run-experiment swapper (list s1 s2 slist) ans
                             equal?)))
        (if (car outcome)
            (eopl:printf "passed ~%")
            (eopl:printf "Failed ~%")
            )
        )
      )
  )
;;The Actual Tests
(display "\n------------\nTesting Swapper\n------------\n")    
(test-swapper 'swap1 'a 'd '(a d b c) '(d a b c))
(test-swapper 'swap1 'a 'd '(a d () c d) '(d a () c a))
(test-swapper 'swap1 'x 'y '((x) y (z (x))) '((y) x (z (y))))
;;------------------------------------------------
;;1.18 Tests for count occurences
(require "count-occurrences.scm")  

(define test-ct-occur
(lambda(tst s1 slist ans)
   (eopl:printf "~s " tst)
      (let ((outcome
             (run-experiment count-occurrences (list s1  slist) ans
                             equal?)))
        (if (car outcome)
            (eopl:printf "passed ~%")
            (eopl:printf "Failed ~%")
            )
        )
      )
  )  
(display "\n------------\nTesting Count-Occurences\n------------\n")    
(test-ct-occur 'count1 'x '((f x)) 1)
(test-ct-occur 'count2 'x '((f x) y (((x z) () x))) 3)
(test-ct-occur 'count3 'w '((f x) y (((x z) x))) 0)

;;------------------------------------------------
;; 1.20 Tests for Product
(require "product.scm")
(define test-product
(lambda(tst slist1 slist2 ans)
   (eopl:printf "~s " tst)
      (let ((outcome
             (run-experiment product (list  slist1 slist2) ans
                             equal?)))
        (if (car outcome)
            (eopl:printf "passed ~%")
            (eopl:printf "Failed ~%")
            )
        )
      )
  )  
(display "\n------------\nTesting Product\n------------\n")    
(test-product 'prod1 '(a b c) '(x y) '((a x) (a y) (b x) (b y) (c x) (c y)))

;;------------------------------------------------
;;1.21
(require "filter-in.scm")
(define test-filter-in
(lambda(tst pred slist2 ans)
   (eopl:printf "~s " tst)
      (let ((outcome
             (run-experiment filter-in (list  pred slist2) ans
                             equal?)))
        (if (car outcome)
            (eopl:printf "passed ~%")
            (eopl:printf "Failed ~%")
            )
        )
      )
  )    
(display "\n------------\nTesting Filter-In\n-------\n")  
(test-filter-in 'filter-in1 number? '(a 2 (1 3) b 7) '(2 7))
(test-filter-in 'filter-in2 symbol? '(a (b c) 17 foo) '(a foo))  
;;------------------------------------------------
;;1.22
(require "list-index.scm")
(define test-list-index
(lambda(tst pred slist2 ans)
   (eopl:printf "~s " tst)
      (let ((outcome
             (run-experiment list-index (list  pred slist2) ans
                             equal?)))
        (if (car outcome)
            (eopl:printf "passed ~%")
            (eopl:printf "Failed ~%")
            )
        )
      )
  )    
(display "\n------------\nTesting List-Index\n------------\n")  
(test-list-index 'list-index1 number? '(a b 1 2) '2)
(test-list-index 'list-index2 symbol? '(a b 1 2) '0)  
(test-list-index 'list-index2 symbol? '(12 (a c) 5) '#f)    
  
;;-----------------------------------------------
;;1.23
;;Tests fir every?
(require "every.scm")

(define test-every
  (lambda (tst pred lst ans)
    (eopl:printf "~s " tst)
    (let ((outcome
           (run-experiment every? (list pred lst) ans
                           equal?)))
      (if (car outcome)
          (eopl:printf "passed ~%")
          (eopl:printf "Failed ~%")
          )
      )
    )
  )
  ;;  The actual tests
  (display "\n------------\nTesting every?\n------------\n") 
(test-every 'every1 number? '(a 1 3 5) '#f)
(test-every  'every2 symbol? '(a f d) '#t)  
  
;;-----------------------------------------------
 ;;1.27
;;Tests fir merge
(require "merge.scm")

(define test-merge
  (lambda (tst lst1 lst2 ans)
    (eopl:printf "~s " tst)
    (let ((outcome
           (run-experiment merge (list lst1 lst2) ans
                           equal?)))
      (if (car outcome)
          (eopl:printf "passed ~%")
          (eopl:printf "Failed ~%")
          )
      )
    )
  ) 
  ;;  The actual tests
  (display "\n------------\nTesting merge\n------------\n") 
(test-merge 'merge1 '(1 4) '(1 2 8) '(1 1 2 4 8) )
(test-merge 'merge2 '(35 62 81 90 91) '(3 83 85 90)  '(3 35 62 81 83 85 90 90 91))
  
;;-----------------------------------------------

;;1.26 Test for flatten  
(require "flatten.scm")

(define test-flat
  (lambda (tst lst ans)
    (eopl:printf "~s " tst)
    (let ((outcome
           (run-experiment flatten (list lst) ans
                           equal?)))
      (if (car outcome)
          (eopl:printf "passed ~%")
          (eopl:printf "Failed ~%")
          )
      )
    )
  )

;;  The actual tests
  (display "\n------------\nTesting Flatten\n------------\n")    
  (test-flat 'flat1 '(a b c) '(a b c))
  (test-flat 'flat1 '((a) () ((b) ()) () (c)) '(a b c))
  (test-flat 'flat1 '((a b) c (((d)) e)) '(a b c d e))
;;  (test-flat 'flat1 '(a b (() (c) )) '(a b c))



);; end of module top